package com.powernode.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.Prod;
import com.powernode.model.Result;
import com.powernode.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @create: 2024/7/24
 * @author: gyhe10
 * @description: 搜索业务控制层
 **/

@Api(tags = "搜索业务接口管理")
@RestController
public class SearchController {

    @Resource
    private SearchService searchService;

    /**
     * 根据分组标签id分页查询商品列表
     * @param tagId 分组标签id
     * @param current 当前页码
     * @param size 每页显示记录数
     * @return
     */
    @ApiOperation("根据分组标签id查询商品列表")
    @GetMapping("/prod/prodListByTagId")
    public Result<Page<Prod>> loadWxProdPageByTag(@RequestParam Long tagId,
                                                  @RequestParam(defaultValue = "1") Long current,
                                                  @RequestParam Long size) {
        // 根据分组标签id分页查询商品列表
        Page<Prod> page = searchService.queryProdPageByTagId(tagId, current, size);
        return Result.success(page);
    }

    /**
     * 根据商品类目id查询商品集合
     * @param categoryId 商品类目id
     * @return
     */
    @ApiOperation("根据商品类目id查询商品集合")
    @GetMapping("prod/category/prod/list")
    public Result<List<Prod>> loadWxProdListByCategoryId(@RequestParam Long categoryId) {
        // 根据商品类目id查询商品集合
        List<Prod> prodList = searchService.queryWxProdListByCategoryId(categoryId);
        return Result.success(prodList);
    }
}
